package com.ruoyi.article.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.article.domain.TempAticle;
import com.ruoyi.article.service.ITempAticleService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 通过爬虫爬来的数据Controller
 * 
 * @author ruoyi
 * @date 2022-02-11
 */
@RestController
@RequestMapping("/aticle/temp")
public class TempAticleController extends BaseController
{
    @Autowired
    private ITempAticleService tempAticleService;

    /**
     * 查询通过爬虫爬来的数据列表
     */
    @PreAuthorize("@ss.hasPermi('aticle:temp:list')")
    @GetMapping("/list")
    public TableDataInfo list(TempAticle tempAticle)
    {
        startPage();
        List<TempAticle> list = tempAticleService.selectTempAticleList(tempAticle);
        return getDataTable(list);
    }

    /**
     * 导出通过爬虫爬来的数据列表
     */
    @PreAuthorize("@ss.hasPermi('aticle:temp:export')")
    @Log(title = "通过爬虫爬来的数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TempAticle tempAticle)
    {
        List<TempAticle> list = tempAticleService.selectTempAticleList(tempAticle);
        ExcelUtil<TempAticle> util = new ExcelUtil<TempAticle>(TempAticle.class);
        util.exportExcel(response, list, "通过爬虫爬来的数据数据");
    }

    /**
     * 获取通过爬虫爬来的数据详细信息
     */
    @PreAuthorize("@ss.hasPermi('aticle:temp:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tempAticleService.selectTempAticleById(id));
    }

    /**
     * 新增通过爬虫爬来的数据
     */
    @PreAuthorize("@ss.hasPermi('aticle:article:add')")
    @Log(title = "通过爬虫爬来的数据", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TempAticle tempAticle)
    {
        return toAjax(tempAticleService.insertTempAticle(tempAticle));
    }

    /**
     * 修改通过爬虫爬来的数据
     */
    @PreAuthorize("@ss.hasPermi('aticle:temp:edit')")
    @Log(title = "通过爬虫爬来的数据", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TempAticle tempAticle)
    {
        return toAjax(tempAticleService.updateTempAticle(tempAticle));
    }

    /**
     * 删除通过爬虫爬来的数据
     */
    @PreAuthorize("@ss.hasPermi('aticle:temp:remove')")
    @Log(title = "通过爬虫爬来的数据", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tempAticleService.deleteTempAticleByIds(ids));
    }

    /**
     * 删除通过爬虫爬来的数据
     */
    @PreAuthorize("@ss.hasPermi('aticle:temp:remove')")
    @Log(title = "通过爬虫爬来的数据", businessType = BusinessType.DELETE)
    @PostMapping("/saveToArticle")
    public AjaxResult saveToArticle(@RequestBody TempAticle tempAticle)
    {
        return toAjax(tempAticleService.saveToArticle(tempAticle));
    }
}
